//
//  LoanWebTipManager.m
//
//
//  Created by 王晓萌 on 17/5/3.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "LoanWebTipManager.h"
#import "ClientApi.h"
#import "NotificationManager.h"

@interface LoanWebTipManager ()


@property (nonatomic,strong) NSMutableArray *tempArray;

@end

@implementation LoanWebTipManager


+(instancetype)shareInstance{
  static dispatch_once_t onceToken;
  static id instance = nil;
  dispatch_once(&onceToken, ^{
    instance = [[self alloc] init];
  });
  return instance;
}

- (NSMutableArray *)tempArray{
  if (!_tempArray) {
    _tempArray = [NSMutableArray arrayWithCapacity:30];
  }
  return _tempArray;
}

- (void)initTempArrayWithArray:(NSArray *)originArray{
  self.tempArray = [NSMutableArray arrayWithArray:originArray];
}

- (void)initNormal{
  [self initTempArrayWithArray:[LoanWebTipManager getLoanListArray]];
}

- (void)deleteTempObjc:(id)objc{
  if ([self.tempArray containsObject:objc]) {
    [self.tempArray removeObject:objc];
  }
}
- (NSArray *)getLoanListArrayTemp{
  return self.tempArray.copy;
}


- (void)getLoanListWebStatusWithCallBack:(void (^)(id error_msg ,id data))callBack{
  [[ClientApi getInstance] getZQLoanListStatuWithCallBack:^(id  _Nullable responseObject, NSError * _Nullable error) {
    if (error) {
      GYNLog(@"error = %@",error);
      callBack(error.description,nil);
    }else{
      GYNLog(@"response = %@",responseObject);
      callBack(nil,responseObject);
    }
  }];
}

- (void)start{
  [self getLoanListWebStatusWithCallBack:nil];
}

+ (LoanWebTipModel *)getStatusModel{
  return [[NotificationManager getInstance] tipModel];
}

+ (NSArray *)getLoanListArray{
  LoanWebTipModel *tipModel = [self getStatusModel];
  return tipModel.loan_list;
}

+ (NSString *)getDownLoadURL{
  NSString *url = @"";
  LoanWebTipModel *tipModel = [self getStatusModel];
  if (tipModel.download_url && tipModel.download_url.allKeys.count > 0) {
    NSArray *iosURLArray = tipModel.download_url[@"ios"];
    if (iosURLArray && iosURLArray.count > 0) {
      for (NSDictionary *urlDic in iosURLArray) {
        NSInteger app_no = [urlDic[@"app_no"] integerValue];
        if (app_no != APP_NO.integerValue ) {
          url = urlDic[@"url"];
          break;
        }
      }
    }
  }
  return url;
}



@end


@implementation LoanWebTipModel

+(id)getLoanWebTipModel:(id)data{
  id detailData = [LoanWebTipModel mj_objectWithKeyValues:data];
  return detailData ;
}


+ (NSDictionary *)mj_objectClassInArray{
  return @{
           @"loan_list":@"LoanTipDetailModel"
           };
  //    }
}

@end


@implementation LoanTipDetailModel

-(instancetype)init{
  if (self = [super init]) {
    [LoanTipDetailModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
      return @{@"ID" : @"id"
               };
    }];

  }
  return self;
}

@end
